<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

	<div class="signin_signup_form">
		<div id="signin_signup_error_msg"
			class="signin_signup_msg_box"
			style="${ not empty msgError ? 'display:block;' : 'display:none;' }">
			<c:forEach items="${ msgError }" var="itemError">
				<div> ${ itemError } </div>
			</c:forEach>
		</div>
		
		<div class="signin_signup_title">
			<tiles:insertAttribute name="msg.title"/>
		</div>
		
		<div id="signin_signup_success_msg"
			class="signin_signup_msg_box"
			style="${ not empty msgSuccess ? 'display:block;' : 'display:none;' }">
			<c:forEach items="${ msgSuccess }" var="itemSuccess">
				<div> ${ itemSuccess } </div>
			</c:forEach>
		</div>
		
		<tiles:insertAttribute name="form"/>
		
		<div style="margin-top: 40px;">
			<tiles:insertAttribute name="links"/>
		</div>
	</div>
	
	<script type="text/javascript">
		$( document ).ready( function() {
			$( ':input:enabled:visible:first' ).focus();
			$( 'form' ).submit( function( event ) {
				var $errorBox, errorMsg = '', $emailAddress, $password, $confirmPassword, emailRegex = /<spring:message code="field.regex.emailaddress"/>/;
				
				$emailAddress = $( "input#emailAddress" );
				$password = $( "input#password" );
				$confirmPassword = $( "input#confirm_password" );
				
				if ( !emailRegex.test( $emailAddress.val() ) ) {
					errorMsg += "<div> <spring:message code='field.error.emailaddress'/> </div>";
				}
				if ( $password.val().length < 8 ) {
					errorMsg += "<div> <spring:message code='field.error.password'/> </div>";
				} else  if ( $confirmPassword.length && ( $password.val() != $confirmPassword.val() ) ) {
					errorMsg += "<div> <spring:message code='field.error.confirm_password'/> </div>";
				}
				
				if ( errorMsg ) {
					$errorBox = $( '#signin_signup_error_msg' );
					$errorBox.empty();
					$errorBox.html( errorMsg );
					$errorBox.show();
					event.preventDefault();
				}
			} );
		} );
	</script>